package com.learn;

import java.sql.Connection;

import javax.sql.DataSource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

/**
 * springboot装配DataSource的步骤
 * 1.引入依赖
 * 2.配置
 *  spring.datasource.driverClassName=com.mysql.jdbc.Driver
	spring.datasource.url=jdbc:mysql://127.0.0.1:3306/sbootv
	spring.datasource.username=root
	spring.datasource.password=root
	
	以上操作，springboot会自动装配好DataSource,JdbcTemplate,可以直接使用
	
	spring.datasource.type可以指定具体使用哪种数据源
	默认支持tomcat-jdbc，Hikari，dbcp.dbcp2
	
3.配置自定义的datasource:
	只需要装配一个DataSource到spring容器中即可，如{@com.learn.DBConfig}
	
4.事务：@Transactional
 * @author Romanceling
 *
 */
@SpringBootApplication
public class App {
    public static void main( String[] args ) throws Exception{
        ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
        System.out.println(context.getBean(DataSource.class));
        DataSource ds = context.getBean(DataSource.class);
//        Connection conn = ds.getConnection();
//        conn.close();
        context.getBean(JdbcDao.class).addProductBatch("name1","name2");
        System.out.println(ds.getClass());
    }
}
